import request from '@/utils/request'

/**
 * 订单结算
 * @param {*} mode
 *  mode：cart  obj => { cartIds }
 *  mode: buyNow  obj => { goodsId,goodsNum,goodsSkuId }
 * @param {*} obj
 * @returns
 */
export const checkOrder = (mode, obj) => {
  return request.get('/checkout/order', {
    params: {
      mode, // 是购物车下单传cart，是商品详情页立即购买下单传buyNow
      delivery: 10, // 10 快递配送 20 门店自提
      couponId: 0, // 优惠券 ID，0代表不适用优惠券
      isUsePoints: 0, // 积分，0表示不使用积分
      ...obj // 将传递过来的参数对象动态展开
    }
  })
}

/**
 * 提交订单
 * @param {*} mode
 *  mode：cart  obj => { cartIds, remark }
 *  mode: buyNow  obj => { goodsId, goodsNum, goodsSkuId, remark }
 * @param {*} obj
 * @returns
 */
export const submitOrder = (mode, obj) => {
  return request.post('/checkout/submit', {
    mode,
    delivery: 10, // 10 快递配送 20 门店自提
    couponId: 0, // 优惠券 ID，0代表不适用优惠券
    isUsePoints: 0, // 积分，0表示不使用积分
    payType: 10, // 余额支付
    ...obj // 将传递过来的参数对象动态展开
  })
}

// 订单列表
export const getMyOrderList = (dataType, page) => {
  return request.get('/order/list', {
    params: {
      dataType,
      page
    }
  })
}

// 取消订单
export const cancelOrder = (orderId) => {
  return request.post('/order/cancel', {
    orderId
  })
}

// 订单确认收货
export const orderReceipt = (orderId) => {
  return request.post('/order/receipt', {
    orderId
  })
}
